<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script src="util.js"></script>
<script>
    function shell(arr) {
      let n = arr.length;
      let h = 1;
      while (h < n / 3) {
        h = 3*h + 1;
      }

      while (h >= 1) {
        for (let i = h; i < n; i ++) {
          for (let j = i; j >= h; j -= h) {
            console.log(j + ',' + (j - h));
            if (arr[j] < arr[j - h]) {
              exec(arr, j, j - h);
            }
            console.log(arr);

          }
        }
        h=(h-1)/3;
        console.log('change gap: ', h);
      }
    }

    test_arr = [8, 1, 4, 3, 5, 9];
    shell(test_arr);
    console.log(test_arr);

</script>
</html>